package me.sentinel;

import java.util.Iterator;
import java.util.function.Consumer;

public class Test2 {
    public static void main(String[] args) {
        SinglyLinkedListSentinel sle = new SinglyLinkedListSentinel();
        sle.addFirst(1);
        sle.addFirst(2);
        sle.addFirst(3);
        sle.addFirst(4);
        sle.addLast(5);
        sle.addLast(6);

        sle.loop2(value -> {
            System.out.println(value);
        });
        System.out.println("----------------------");

        // loop1简化前
        sle.loop2(new Consumer<Integer>() {
            @Override
            public void accept(Integer value) {
                System.out.println(value);
            }
        });
        System.out.println("-----------------------");

        //增强for遍历，底层依赖迭代器
        for (Integer value : sle) {
            System.out.println(value);
        }
        System.out.println("-----------------------");
        //获取节点的值
        System.out.println(sle.get(2));
        System.out.println("-----------------------");
        //任意位置插入
        sle.insert(4, 10);
        sle.insert(6, 12);

        sle.removeFirst();

        sle.remove(3);
        //迭代器遍历
        Iterator<Integer> it = sle.iterator();
        while (it.hasNext()) {
            System.out.println(it.next() + " ");
        }
    }
}
